package com.example.timernote

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import kotlinx.android.synthetic.main.activity_add_note.*
import java.text.SimpleDateFormat
import java.util.*

class AddNoteActivity : AppCompatActivity() {

    private lateinit var bloodPressureInfo: BloodPressureInfo

    lateinit var dateTimeStr:String


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_note)

        mTvDateTime.text = initDateTimeStr()

        mBtnSave.setOnClickListener(object : View.OnClickListener{
            override fun onClick(v: View?) {
                saveNote()
            }
        })

    }

    private fun saveNote() {
        var dateStrArray = dateTimeStr.split(" ")

        bloodPressureInfo = BloodPressureInfo(
            mEtBPLow.text.toString(),
            mEtBPHigh.text.toString(),
            mEtBPRate.text.toString(),
            dateStrArray[0],
            dateStrArray[1]
        )

        Log.d("saveBP",bloodPressureInfo.toString())
        BloodPressureInfoService.add(bloodPressureInfo)
        finish()
    }

    private fun initDateTimeStr(): String? {
        var sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        dateTimeStr = sdf.format(Date())
        return dateTimeStr
    }




}
